﻿using checc_baseTools.CaveMouth.Entity;
using Culvert_Help;
using NeXus.BIMBase;
using NeXus.BIMBase.Core;
using NeXus.p3d;
using System;
using System.Collections.Generic;
using static NeXus.p3d.GeCurveArray;

namespace checc_baseTools.CaveMouth
{
    public class SideDitchDropWells
    {
        #region Fileds

        // 井底厚度	
        private static double _sideDitchFallWell_ShaftBottomThickness;
        // 井底宽度	
        private static double _sideDitchFallWell_ShaftBottomBreadth;
        // 沉砂池深	
        private static double _sideDitchFallWell_GritBasinDeep;
        // 井底中心长	
        private static double _sideDitchFallWell_ShaftBottomCenterLength;
        // 井深		
        private static double _sideDitchFallWell_ShaftDeep;
        // 井壁顶宽	
        private static double _sideDitchFallWell_ShaftWallTopWidth;
        // 井壁坡比1: n
        private static double _sideDitchFallWell_ShaftWallSlopeRatio;
        // 井外平台宽	
        private static double _sideDitchFallWell_ShaftOuterWidth;
        // 井外开挖坡度
        private static double _sideDitchFallWell_ShaftOuterSlope;
        // 边沟外壁偏距
        private static double _sideDitchFallWell_SideDitchOutWallSetover;
        // 边沟深度	
        private static double _sideDitchFallWell_SideDitchDeep;
        // 边沟内坡比	
        private static double _sideDitchFallWell_SideDitchInSlopeRatio;
        // 边沟底宽	
        private static double _sideDitchFallWell_SideDitchBottomWidth;
        // 边沟外坡比	
        private static double _sideDitchFallWell_SideDitchOutSlopeRatio;
        // 外壁护面高	
        private static double _sideDitchFallWell_OutWallMaskHeight;
        // 护面坡比1: n
        private static double _sideDitchFallWell_MaskSlopeRatio;
        // 左端开口长	
        private static double _sideDitchFallWell_FirstMemberStartTalkLength;
        // 右端开口长	
        private static double _sideDitchFallWell_RightMemberStartTalkLength;
        // 边沟绘制长
        private static double _sideDitchFallWell_SideDitchDrawLength;
        // 井底纵坡	
        private static double _sideDitchFallWell_ShaftBottomEndlongSlope;
        // 是否选用自动计算的井深
        private static bool _sideDitchFallWell_CheckAuto;

        private static string _clearSpan = null;
        private static string _clearHeight = null;

        #endregion
        public static void CreateSideDitchFallWell(SideDitchDropWellData sideDitchFallWell, double distance_W, double distance_H, double angle)
        {
            _sideDitchFallWell_ShaftBottomThickness = sideDitchFallWell.SideDitchFallWell_ShaftBottomThickness * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_GritBasinDeep = sideDitchFallWell.SideDitchFallWell_GritBasinDeep * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftBottomCenterLength = sideDitchFallWell.SideDitchFallWell_ShaftBottomCenterLength * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftDeep = sideDitchFallWell.SideDitchFallWell_ShaftDeep * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftWallTopWidth = sideDitchFallWell.SideDitchFallWell_ShaftWallTopWidth * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftWallSlopeRatio = sideDitchFallWell.SideDitchFallWell_ShaftWallSlopeRatio;
            _sideDitchFallWell_ShaftOuterWidth = sideDitchFallWell.SideDitchFallWell_ShaftOuterWidth * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftOuterSlope = sideDitchFallWell.SideDitchFallWell_ShaftOuterSlope;
            _sideDitchFallWell_SideDitchOutWallSetover = sideDitchFallWell.SideDitchFallWell_SideDitchOutWallSetover * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_SideDitchDeep = sideDitchFallWell.SideDitchFallWell_SideDitchDeep * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_SideDitchInSlopeRatio = sideDitchFallWell.SideDitchFallWell_SideDitchInSlopeRatio;
            _sideDitchFallWell_SideDitchBottomWidth = sideDitchFallWell.SideDitchFallWell_SideDitchBottomWidth * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_SideDitchOutSlopeRatio = sideDitchFallWell.SideDitchFallWell_SideDitchOutSlopeRatio;
            _sideDitchFallWell_OutWallMaskHeight = sideDitchFallWell.SideDitchFallWell_OutWallMaskHeight * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_MaskSlopeRatio = sideDitchFallWell.SideDitchFallWell_MaskSlopeRatio;
            _sideDitchFallWell_FirstMemberStartTalkLength = sideDitchFallWell.SideDitchFallWell_FirstMemberStartTalkLength * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_RightMemberStartTalkLength = sideDitchFallWell.SideDitchFallWell_RightMemberStartTalkLength * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_SideDitchDrawLength = sideDitchFallWell.SideDitchFallWell_SideDitchDrawLength * Culvert_Help.GeneralHelpers.UOR;
            _sideDitchFallWell_ShaftBottomEndlongSlope = sideDitchFallWell.SideDitchFallWell_ShaftBottomEndlongSlope;
            _sideDitchFallWell_CheckAuto = sideDitchFallWell.SideDitchFallWell_CheckAuto;

            _clearSpan = distance_W.ToString();
            _clearHeight = distance_H.ToString();

        }


        public static BPGraphicsCollection CreateSideDitchFallWellBody(SideDitchDropWellData sideDitchDropWellData, double distance_W, double distance_H, double angle)
        {
            BPProject project = BPApplication.getInstance().getProjectManager().getMainProject();
            BPModelBase model = project.getActiveModel();

            CreateSideDitchFallWell(sideDitchDropWellData, distance_W, distance_H, angle);
            double span = Convert.ToDouble(_clearSpan) * Culvert_Help.GeneralHelpers.UOR;
            double Degrees = angle;

            #region 绘制井底
            double topleftDegrees = 90 - (180 - Degrees);
            //井壁宽
            double topWidth = _sideDitchFallWell_ShaftWallTopWidth;
            //计算井壁坡度
            double addZ = _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_GritBasinDeep;
            double addX = addZ * _sideDitchFallWell_ShaftWallSlopeRatio;
            //计算井底坡度
            double offserOfZ = topWidth * _sideDitchFallWell_ShaftBottomEndlongSlope;
            //被裁掉的长度 
            double addLength = Math.Abs(Math.Tan(topleftDegrees * Math.PI / 180) * (span / 2 + topWidth + addX));

            //double downHeight = addLength * 1.5 * _sideDitchFallWell_ShaftBottomEndlongSlope;

            // 井底左侧点 有坡度剪不到墙 向左侧推一个延申长度
            GePoint3dCollection points_ShaftBottom = new GePoint3dCollection
            {
                new GePoint3d(-addLength, span / 2 + topWidth,  -_sideDitchFallWell_GritBasinDeep),
                new GePoint3d(-addLength, span / 2 + topWidth, -_sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep),
                new GePoint3d(-addLength, -span / 2 - topWidth, -_sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep),
                new GePoint3d(-addLength, -span / 2 - topWidth,  -_sideDitchFallWell_GritBasinDeep),
            };
            // 延x方向构造坡度的线 两侧有坡比 所以构造时 将左侧长度延申一个加长的length
            double length = _sideDitchFallWell_ShaftBottomCenterLength + addLength/* * 2*/ + _sideDitchFallWell_ShaftWallTopWidth/* + addX*/;
            GeVec3d templineElement = GetSlopLinee(length, _sideDitchFallWell_ShaftBottomEndlongSlope);
            GeCurveArray sectiongElement = GeCurveArray.createLinestringArray(points_ShaftBottom, BoundaryType.BOUNDARY_TYPE_Outer, true);
            GeExtrusionInfo extrusionInfo = new GeExtrusionInfo(sectiongElement, templineElement, true);
            IGeSolidBase wellBottom = IGeSolidBase.createGeExtrusion(extrusionInfo);
            BPGraphics wellBottomGP = model.createPhysicalGraphics();
            wellBottomGP.addSolid(wellBottom);

            #endregion

            #region Get well bottom points of top
            /*
             俯视图 第一个点在左下角 逆时针依次为 第二个 第三个
             */
            GePoint3d staP_Bottom = new GePoint3d(-addLength, -span / 2, -_sideDitchFallWell_GritBasinDeep);
            GePoint3d secondP_Bottom = new GePoint3d(length - addLength - topWidth, -span / 2, -_sideDitchFallWell_GritBasinDeep);
            GePoint3d thirdP_Bottom = new GePoint3d(length - addLength - topWidth, span / 2, -_sideDitchFallWell_GritBasinDeep);
            GePoint3d endP_Bottom = new GePoint3d(-addLength, span / 2, -_sideDitchFallWell_GritBasinDeep);
            GePoint3dCollection points_BottomSide = new GePoint3dCollection { staP_Bottom, secondP_Bottom, thirdP_Bottom, endP_Bottom };
            //内部底面
            GeCurveArray inBottomSide = GeCurveArray.createLinestringArray(points_BottomSide, BoundaryType.BOUNDARY_TYPE_Outer, true);

            #endregion

            #region Inner
            GePoint3d staP_Top = new GePoint3d(staP_Bottom.x, staP_Bottom.y - addX, _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep);
            GePoint3d secondP_Top = new GePoint3d(secondP_Bottom.x + addX, secondP_Bottom.y - addX, _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep);
            GePoint3d thirdP_Top = new GePoint3d(thirdP_Bottom.x + addX, thirdP_Bottom.y + addX, _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep);
            GePoint3d endP_Top = new GePoint3d(endP_Bottom.x, endP_Bottom.y + addX, _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep);

            GePoint3dCollection points_TopSide = new GePoint3dCollection { staP_Top, secondP_Top, thirdP_Top, endP_Top };
            //内部顶面
            GeCurveArray inTopSide = GeCurveArray.createLinestringArray(points_TopSide, BoundaryType.BOUNDARY_TYPE_Outer, true);
            //内部体
            IGeSolidBase in_Solid = IGeSolidBase.createGeRuledSweep(new GeRuledSweepInfo(inBottomSide, inTopSide, true));
            #endregion

            #region Outer
            GePoint3d staP_TopOut = new GePoint3d(staP_Top.x, staP_Top.y - topWidth, staP_Top.z);
            GePoint3d secondP_TopOut = new GePoint3d(secondP_Top.x + topWidth, secondP_Top.y - topWidth, secondP_Top.z);
            GePoint3d thirdP_TopOut = new GePoint3d(thirdP_Top.x + topWidth, thirdP_Top.y + topWidth, thirdP_Top.z);
            GePoint3d endP_TopOut = new GePoint3d(endP_Top.x, endP_Top.y + topWidth, endP_Top.z);
            //外部顶面侧点
            GePoint3dCollection points_TopOutSide = new GePoint3dCollection { staP_TopOut, secondP_TopOut, thirdP_TopOut, endP_TopOut };
            //外部顶面
            GeCurveArray outTopSide = GeCurveArray.createLinestringArray(points_TopOutSide, BoundaryType.BOUNDARY_TYPE_Outer, true);


            GePoint3d staP_BottomOut = new GePoint3d(staP_Bottom.x, staP_Bottom.y - topWidth, staP_Bottom.z);
            GePoint3d secondP_BottomOut = new GePoint3d(secondP_Bottom.x + topWidth, secondP_Bottom.y - topWidth, secondP_Bottom.z - offserOfZ);
            GePoint3d thirdP_BottomOut = new GePoint3d(thirdP_Bottom.x + topWidth, thirdP_Bottom.y + topWidth, secondP_Bottom.z - offserOfZ);
            GePoint3d endP_BottomOut = new GePoint3d(endP_Bottom.x, endP_Bottom.y + topWidth, endP_Bottom.z);
            //外部底面侧点
            GePoint3dCollection points_BottomOutSide = new GePoint3dCollection { staP_BottomOut, secondP_BottomOut, thirdP_BottomOut, endP_BottomOut };
            //外部底面
            GeCurveArray outBottomSide = GeCurveArray.createLinestringArray(points_BottomOutSide, BoundaryType.BOUNDARY_TYPE_Outer, true);
            //外部体
            IGeSolidBase out_Solid = IGeSolidBase.createGeRuledSweep(new GeRuledSweepInfo(outBottomSide, outTopSide, true));
            //布尔差集形成边沟 大的减小的 
            BPGraphics sideDitchDropWells = Element_solid.BoolDifferenceSet(out_Solid, in_Solid, false);
            //墙体和底面合集
            sideDitchDropWells = Element_solid.BoolCollection(sideDitchDropWells, wellBottomGP, false);
            #endregion

            #region 边沟
            double gutterLength = staP_TopOut.distance(endP_TopOut);
            GePoint3d lineEndP = GePoint3d.createByZero();
            if (Degrees != 90)
            {
                if (Degrees < 90)
                {
                    lineEndP = Helper.Rotation(staP_TopOut, endP_TopOut, gutterLength / Math.Abs(Math.Cos(topleftDegrees * Math.PI / 180)), topleftDegrees);
                    lineEndP.z = _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep;
                }
                else if (Degrees > 90)
                {
                    lineEndP = Helper.Rotation(endP_TopOut, staP_TopOut, gutterLength / Math.Abs(Math.Cos(topleftDegrees * Math.PI / 180)), topleftDegrees);
                    lineEndP.z = _sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness - _sideDitchFallWell_GritBasinDeep;
                }

                GePoint3d lineStaP = Helper.Rotation(GePoint3d.createByZero(), new GePoint3d(-1, 0, 0), gutterLength / Math.Cos(topleftDegrees * Math.PI / 180), Degrees);
                lineStaP.z = lineEndP.z;
                //剪切体的顶面点
                GePoint3dCollection spliceosomeTopPt = new GePoint3dCollection { staP_TopOut, lineEndP, endP_TopOut };
                //剪切体的顶面
                GeCurveArray spliceosomeTop = GeCurveArray.createLinestringArray(spliceosomeTopPt, BoundaryType.BOUNDARY_TYPE_Outer, true);
                //剪切体
                IGeSolidBase spliceosome_Solid = IGeSolidBase.createGeExtrusion(new GeExtrusionInfo(spliceosomeTop, new GeVec3d(0, 0, -_sideDitchFallWell_ShaftDeep - _sideDitchFallWell_ShaftBottomThickness), true));
                //布尔差集剪切出洞口角度 
                sideDitchDropWells = Element_solid.BoolDifferenceSet(sideDitchDropWells, spliceosome_Solid, false);
            }
            //sideDitchDropWells.save();

            #region first border points

            double leftX = _sideDitchFallWell_SideDitchInSlopeRatio * _sideDitchFallWell_SideDitchDeep;
            double rightX = _sideDitchFallWell_SideDitchDeep * _sideDitchFallWell_SideDitchOutSlopeRatio;
            GePoint3d forwardP1 = GePoint3d.createByZero();
            GePoint3d backP1 = GePoint3d.createByZero();
            if (Degrees < 90)
            {
                forwardP1 = staP_TopOut;
                backP1 = lineEndP;
            }
            else if (Degrees > 90)
            {
                forwardP1 = lineEndP;
                backP1 = endP_TopOut;
            }
            else
            {
                forwardP1 = staP_TopOut;
                backP1 = endP_TopOut;
            }

            GePoint3d forwardP2 = new GePoint3d(forwardP1.x + leftX, forwardP1.y, forwardP1.z - _sideDitchFallWell_SideDitchDeep);
            GePoint3d forwardP4 = new GePoint3d(secondP_TopOut.x - _sideDitchFallWell_SideDitchOutWallSetover - topWidth, secondP_TopOut.y, secondP_TopOut.z);
            GePoint3d forwardP3 = new GePoint3d(forwardP4.x - rightX, forwardP4.y, forwardP4.z - _sideDitchFallWell_SideDitchDeep);
            #endregion

            #region second border points
            GePoint3d backP2 = new GePoint3d(backP1.x + leftX, backP1.y, backP1.z - _sideDitchFallWell_SideDitchDeep);
            GePoint3d backP4 = new GePoint3d(thirdP_TopOut.x - _sideDitchFallWell_SideDitchOutWallSetover - topWidth, thirdP_TopOut.y, thirdP_TopOut.z);
            GePoint3d backP3 = new GePoint3d(backP4.x - rightX, backP4.y, backP4.z - _sideDitchFallWell_SideDitchDeep);

            #endregion

            #region MyRegion
            //前视图凹槽底部外侧两点
            GeCurveArray curveArray1 = GeCurveArray.createLinestringArray(new GePoint3dCollection { secondP_BottomOut, staP_BottomOut, staP_TopOut, secondP_TopOut }, BoundaryType.BOUNDARY_TYPE_Outer, true);
            IGeCurveBase curve1 = curveArray1.getIntersectionsWithPlane(new GePlane3d(forwardP2, new GeVec3d(0, 0, 1)), 0);
            curve1.getSegmentCP().getStartAndEndPoints(forwardP2, forwardP3);

            //后视图凹槽底部外侧两点
            GeCurveArray curveArray2 = GeCurveArray.createLinestringArray(new GePoint3dCollection { thirdP_BottomOut, endP_BottomOut, endP_TopOut, thirdP_TopOut }, BoundaryType.BOUNDARY_TYPE_Outer, true);
            IGeCurveBase curve2 = curveArray2.getIntersectionsWithPlane(new GePlane3d(backP2, new GeVec3d(0, 0, 1)), 0);
            curve2.getSegmentCP().getStartAndEndPoints(backP2, backP3);

            if (Degrees < 90)
            {
                forwardP2.set(staP_TopOut.x + leftX, forwardP2.y, forwardP2.z);
                forwardP3.set(forwardP4.x - rightX, forwardP3.y, forwardP3.z);
                backP2.set(lineEndP.x + leftX, backP2.y, backP2.z);
                backP3.set(backP4.x - rightX, backP3.y, backP3.z);
            }
            else if (Degrees > 90)
            {
                forwardP2.set(lineEndP.x + leftX, forwardP2.y, forwardP2.z);
                forwardP3.set(forwardP4.x - rightX, forwardP3.y, forwardP3.z);
                backP2.set(endP_TopOut.x + leftX, backP2.y, backP2.z);
                backP3.set(backP4.x - rightX, backP3.y, backP3.z);
            }
            else
            {
                forwardP2.set(staP_TopOut.x + leftX, forwardP2.y, forwardP2.z);
                forwardP3.set(forwardP4.x - rightX, forwardP3.y, forwardP3.z);
                backP2.set(endP_TopOut.x + leftX, backP2.y, backP2.z);
                backP3.set(backP4.x - rightX, backP3.y, backP3.z);
            }
            #endregion

            #region create shape
            //前视图左侧面拉伸底面槽底长度
            GePoint3dCollection points_Forward = new GePoint3dCollection { forwardP1, forwardP2, forwardP3, forwardP4 };
            GeCurveArray curveArray_Forward = GeCurveArray.createLinestringArray(points_Forward, BoundaryType.BOUNDARY_TYPE_Inner, true);
            //前视图右侧面拉伸底面槽底长度
            GePoint3dCollection points_Back = new GePoint3dCollection { backP1, backP2, backP3, backP4 };
            GeCurveArray curveArray_Back = GeCurveArray.createLinestringArray(points_Back, BoundaryType.BOUNDARY_TYPE_Outer, true);

            IGeSolidBase sideroadConcavity1 = IGeSolidBase.createGeRuledSweep(new GeRuledSweepInfo(new GeCurveArrayCollection { curveArray_Forward, curveArray_Back }, true));
            sideDitchDropWells = Element_solid.BoolDifferenceSet(sideDitchDropWells, sideroadConcavity1, false);
            #endregion
            #endregion

            #region 左右开口端加长
            double leftLength = _sideDitchFallWell_FirstMemberStartTalkLength;
            double rightLength = _sideDitchFallWell_RightMemberStartTalkLength;


            BPGraphics bPGraphics = model.createPhysicalGraphics();
            //判断左右端开口长是否为零
            if (leftLength != 0 && rightLength != 0)
            {
                GePoint3d backP11 = new GePoint3d(backP1.x, backP1.y + leftLength, backP1.z);
                GePoint3d backP22 = new GePoint3d(backP2.x, backP2.y + leftLength, backP2.z);
                GePoint3d backP33 = new GePoint3d(backP3.x, backP3.y + leftLength, backP3.z);
                GePoint3d backP44 = new GePoint3d(backP4.x, backP4.y + leftLength, backP4.z);

                GePoint3d forwardP11 = new GePoint3d(forwardP1.x, forwardP1.y - rightLength, forwardP1.z);
                GePoint3d forwardP22 = new GePoint3d(forwardP2.x, forwardP2.y - rightLength, forwardP2.z);
                GePoint3d forwardP33 = new GePoint3d(forwardP3.x, forwardP3.y - rightLength, forwardP3.z);
                GePoint3d forwardP44 = new GePoint3d(forwardP4.x, forwardP4.y - rightLength, forwardP4.z);
                GePoint3dCollection leftEntrance = new GePoint3dCollection { backP1, backP2,/* backP3, backP4, backP44, backP33,*/ backP22, backP11, backP1 };
                GePoint3dCollection leftEntrance1 = new GePoint3dCollection { backP2, backP3, backP33, backP22, backP2 };
                GePoint3dCollection leftEntrance2 = new GePoint3dCollection { backP3, backP4, backP44, backP33, backP3 };
                GeCurveArray shap_LeftEntrance = GeCurveArray.createLinestringArray(leftEntrance, BoundaryType.BOUNDARY_TYPE_Outer, true);
                GeCurveArray shap_LeftEntrance1 = GeCurveArray.createLinestringArray(leftEntrance1, BoundaryType.BOUNDARY_TYPE_Outer, true);
                GeCurveArray shap_LeftEntrance2 = GeCurveArray.createLinestringArray(leftEntrance2, BoundaryType.BOUNDARY_TYPE_Outer, true);
                bPGraphics.addCurveArray(shap_LeftEntrance);
                bPGraphics.addCurveArray(shap_LeftEntrance1);
                bPGraphics.addCurveArray(shap_LeftEntrance2);
                GePoint3dCollection rightEntrance = new GePoint3dCollection { forwardP1, forwardP2, forwardP22, forwardP11, forwardP1 };
                GePoint3dCollection rightEntrance1 = new GePoint3dCollection { forwardP2, forwardP3, forwardP33, forwardP22, forwardP2 };
                GePoint3dCollection rightEntrance2 = new GePoint3dCollection { forwardP3, forwardP4, forwardP44, forwardP33, forwardP3 };
                GeCurveArray shap_RightEntrance = GeCurveArray.createLinestringArray(rightEntrance, BoundaryType.BOUNDARY_TYPE_Outer, true);
                GeCurveArray shap_RightEntrance1 = GeCurveArray.createLinestringArray(rightEntrance1, BoundaryType.BOUNDARY_TYPE_Outer, true);
                GeCurveArray shap_RightEntrance2 = GeCurveArray.createLinestringArray(rightEntrance2, BoundaryType.BOUNDARY_TYPE_Outer, true);
                bPGraphics.addCurveArray(shap_RightEntrance);
                bPGraphics.addCurveArray(shap_RightEntrance1);
                bPGraphics.addCurveArray(shap_RightEntrance2);
                //bPGraphics.save();
            }
            #endregion

            #region cut 
            //List<GePoint3d> point3Ds = new List<GePoint3d>
            //{
            //    Helper.Rotation(new GePoint3d(), new GePoint3d(1, 0, 0), span * 10, Degrees),
            //    Helper.Rotation(new GePoint3d(), new GePoint3d(-1, 0, 0), span * 10, Degrees),
            //    Helper.Extend_or_Contract(new GePoint3d(), new GePoint3d(-1, 0, 0), span * 10),
            //    Helper.Rotation(new GePoint3d(), new GePoint3d(1, 0, 0), span * 10, Degrees),
            //};
            //GeCurveArray shearPlane = GeCurveArray.createLinestringArray(point3Ds, GeCurveArray.BoundaryType.Outer, true);
            //IGeSolidBase shearedBody = Element_solid.getTensileBody(new GeExtrusionInfo(shearPlane, new GeVec3d(0, 0, _sideDitchFallWell_ShaftDeep), true));

            ////布尔差集剪出洞口位置
            //sideDitchDropWells = Element_solid.BoolDifferenceSet(sideDitchDropWells, shearedBody, false);
            #endregion


            #region 外壁湖面
            GePoint3d staP_ProtectWall = new GePoint3d(secondP_TopOut.x - topWidth, secondP_TopOut.y, secondP_TopOut.z);
            GePoint3d secondP_ProtectWall = secondP_TopOut;
            GePoint3d thirdP_ProtectWall = thirdP_TopOut;
            GePoint3d endP_ProtectWall = new GePoint3d(thirdP_TopOut.x - topWidth, thirdP_TopOut.y, thirdP_TopOut.z);
            GePoint3dCollection points_ProtectWall = new GePoint3dCollection { staP_ProtectWall, secondP_ProtectWall, thirdP_ProtectWall, endP_ProtectWall };

            GeCurveArray curveArray = GeCurveArray.createLinestringArray(points_ProtectWall, BoundaryType.BOUNDARY_TYPE_Outer, true);
            GeVec3d lineElement_ProtectWall = GetSlopLinee(secondP_ProtectWall, _sideDitchFallWell_OutWallMaskHeight, _sideDitchFallWell_ShaftOuterSlope);
            IGeSolidBase protectiveSurface = IGeSolidBase.createGeExtrusion(new GeExtrusionInfo(curveArray, lineElement_ProtectWall, true));
            BPGraphics protectiveSurfaceGP = model.createPhysicalGraphics();
            protectiveSurfaceGP.addSolid(protectiveSurface);
            sideDitchDropWells = Element_solid.BoolCollection(sideDitchDropWells, protectiveSurfaceGP, false);


            //返回边沟跌井顶面四个点的平面
            GeFaceIndicesCollection geFaceIndicesCollection = protectiveSurface.getFaceIndices();
            IGeometry faces = protectiveSurface.getFace(geFaceIndicesCollection[1]);
            GePoint3d StartPoint = faces.getAsGeCurveArray().getStartPoint();//拿指定面上的起点
            BPGraphics plan = GeneralHelpers.Model2D.createPhysicalGraphics();
            GePoint3dCollection planPoint = new GePoint3dCollection();
            GePoint3d point3d1 = GePoint3d.createByZero();
            GePoint3d point3d4 = GePoint3d.createByZero();
            if (Degrees != 90)
            {
                if (Degrees < 90)
                {
                    planPoint = new GePoint3dCollection
                    {
                        new GePoint3d(staP_TopOut.x, staP_TopOut.y, StartPoint.z),
                        new GePoint3d(StartPoint.x + topWidth, StartPoint.y, StartPoint.z),
                        new GePoint3d(StartPoint.x + topWidth, StartPoint.y + span + addX * 2 + + topWidth * 2, StartPoint.z),
                        new GePoint3d(lineEndP.x, lineEndP.y, StartPoint.z),
                    };
                }
                else if (Degrees > 90)
                {
                    planPoint = new GePoint3dCollection
                    {
                        new GePoint3d(lineEndP.x, lineEndP.y, StartPoint.z),
                        new GePoint3d(StartPoint.x + topWidth, StartPoint.y, StartPoint.z),
                        new GePoint3d(StartPoint.x + topWidth, StartPoint.y + span + addX * 2 + + topWidth * 2, StartPoint.z),
                        new GePoint3d(endP_TopOut.x, endP_TopOut.y, StartPoint.z)
                    };
                }
            }
            else
            {
                planPoint = new GePoint3dCollection
                {
                    new GePoint3d(staP_TopOut.x, staP_TopOut.y, StartPoint.z),
                    new GePoint3d(StartPoint.x + topWidth, StartPoint.y, StartPoint.z),
                    new GePoint3d(StartPoint.x + topWidth, StartPoint.y + span + addX * 2 + + topWidth * 2, StartPoint.z),
                    new GePoint3d(endP_TopOut.x, endP_TopOut.y, StartPoint.z)
                };
            }
            GeCurveArray geCurveArray = GeCurveArray.createLinestringArray(planPoint, BoundaryType.BOUNDARY_TYPE_Outer, true);
            plan.addGeCurveArray(geCurveArray);
            return new BPGraphicsCollection { sideDitchDropWells, bPGraphics, plan };
            #endregion


            #region 外壁护面

            //SubEntity[] subEntities;
            //Bentley.DgnPlatformNET.SolidUtil.GetBodyVertices(out subEntities, soild_ProtectWall);

            //SolidUtil.EvaluateVertex(out GePoint3d pointsFirst, subEntities[1]); // Y轴正方向上的点
            //SolidUtil.EvaluateVertex(out GePoint3d pointsSecond, subEntities[2]); // Y轴负方向上的点

            //double offsetX = Math.Abs(pointsFirst.x - pointsSecond.x);
            //double addX_ShaftOuterWidth = _sideDitchFallWell_ShaftOuterWidth;
            //GePoint3d pointsThird = new GePoint3d(pointsSecond.x + addX_ShaftOuterWidth, pointsSecond.y, pointsSecond.z);
            //第三个点需要找到边坡线交点
            //第五个点和第六个点 = 第三个点和第四个点的x - offsetX

            //SolidUtil.EvaluateVertex(out GePoint3d staP, subEntities[1]);
            //SolidUtil.EvaluateVertex(out GePoint3d endP, subEntities[2]);
            //DSegment3d dSegment3D = new DSegment3d(staP, endP);
            //new LineElement(GeneralBank.Default3DModel, null, dSegment3D).AddToModel(); return;

            #endregion
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="shaftBottomCenterLength">跌水井水平长度</param>
        /// <param name="slop">坡度; (输入界面值, 例: 3%则输入3)</param>
        /// <param name="isNegative">是否为负数</param>
        /// <returns></returns>
        public static GeVec3d GetSlopLinee(double shaftBottomCenterLength, double slop, bool isNegative = false)
        {
            double z = shaftBottomCenterLength * slop;
            GeVec3d vec3D = GeVec3d.create(0, 0, 0);
            if (isNegative != true)
            {
                vec3D = GeVec3d.createByStartEnd(GePoint3d.createByZero(), new GePoint3d(shaftBottomCenterLength, 0, z));
                return vec3D;
            }
            else
            {
                vec3D = GeVec3d.createByStartEnd(GePoint3d.createByZero(), new GePoint3d(-shaftBottomCenterLength, 0, z));
                return vec3D;
            }
        }

        public static GeVec3d GetSlopLinee(GePoint3d startPoint, double shaftBottomCenterLength, double slop)
        {
            double x = shaftBottomCenterLength * slop;
            GePoint3d endPoint = new GePoint3d(startPoint.x + x, startPoint.y, startPoint.z + shaftBottomCenterLength);
            GeVec3d vec3D = GeVec3d.createByStartEnd(startPoint, endPoint);
            return vec3D;
        }

        //创建面
        public static PolyfaceHandle CreatePolyfaceHeader(GePoint3dCollection downGePoint3ds, GePoint3dCollection topGePoint3ds)
        {
            GePoint3dCollection GePoint3dTops = new GePoint3dCollection();
            GePoint3dTops.AddRange(downGePoint3ds);

            GePoint3dCollection GePoint3dTopDowns = new GePoint3dCollection();
            GePoint3dTopDowns.AddRange(topGePoint3ds);

            GePoint3dTopDowns.Reverse();
            GePoint3dTops.AddRange(GePoint3dTopDowns);

            PolyfaceHandle polyHeader = PolyfaceHandle.createVariableSizeIndexed();
            polyHeader.addPolygon(GePoint3dTops);
            return polyHeader;
        }
    }
}